package org.xqyy.eval.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.xqyy.eval.model.TSuggestion;
import org.xqyy.eval.model.TSystemCycle;
import org.xqyy.eval.model.TUser;
import org.xqyy.eval.service.ITSuggestionService;
import org.xqyy.eval.service.impl.SystemCycleService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 合理化建议controller
 */
@Controller
@RequestMapping("/suggestion")
public class SuggestionController {
    @Autowired
    private ITSuggestionService suggestionService;
    @Autowired
    private SystemCycleService systemCycleService;
    @RequestMapping("addTSuggestion")
    @ResponseBody
    public  Boolean addTSuggestion(TSuggestion tSuggestion, HttpServletRequest request){
        try {
            HttpSession session = request.getSession();
            TUser user = (TUser)  session.getAttribute("user");
            TSystemCycle systemCycle = systemCycleService.selectNowDate();
            tSuggestion.setEvalyearmonth(systemCycle.getCycledate());
            tSuggestion.setDutyid(user.getDeptId());
            suggestionService.addTSuggestion(tSuggestion);
            return  true;
        } catch (Exception e) {
            e.printStackTrace();
            return  false;
        }
    }
}
